<template>
  <div>
    <h1 id="show"></h1>
  </div>
</template>
<script setup>
import { onMounted, reactive, ref } from "vue";
import { getInfo } from "@/api/login";
import { checkIdCard } from "@/api/transfer/index";
import { updatePersonnelByIdCard } from "@/api/personnel/personnel";

const router = useRouter();
const loginUserId = ref();
const userInfo = ref({});
const data = reactive({
  showText: "",
});

onMounted(() => {
  getInfo().then((res) => {
    loginUserId.value = res.user.userId;
    checkIdCard(res.user.userId).then((result) => {
      const params = new URLSearchParams(window.location.search);
      const totalAmount = params.get("total_amount");
      if (totalAmount === "128.80") {
        //处理支付成功的逻辑
        data.showText = "支付成功";
        document.getElementById("show").innerText = data.showText;
        console.log(result.data.userIdCard);
        updatePersonnelByIdCard(result.data.userIdCard).then((res) => {
          //跳转到支付页面
          if (res.code == 200) {
            router.push({
              path: "/personnel/payFee"
            });
          }
        });
      } else {
        //处理支付失败的逻辑
        data.showText = "支付失败";
        document.getElementById("show").innerText = data.showText;
      }
    });
  });
});
</script>